package cn.xfdzx.android.apps.shop.activity.remake;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.remake.FragmentBigAdapter;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.fragment.BigImage_Fragment;
import cn.xfdzx.android.apps.shop.view.NoScrollViewPager;

/**
 * author：zhengfeng on 2018/9/19 16:32
 * 查看大图activity
 */
public class BigImageViewActivity extends FragmentActivity {
    NoScrollViewPager viewpager;
    private ArrayList<String> imgs;
    private List<Fragment> fragmentList;
    private int position;


    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //EventBus.getDefault().register(this);
//        WindowManager m = getWindowManager();
//        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
//        android.view.WindowManager.LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值
//        p.height = (int) (d.getHeight() * 0.6);   //高度设置为屏幕的0.6
//        p.width = (int) (d.getWidth() * 0.6);    //宽度设置为屏幕的0.95
//        getWindow().setAttributes(p);     //设置生效
        // 隐藏标题栏
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        // 隐藏手机状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_bigimg);
        imgs=getIntent().getStringArrayListExtra("imgs");
        position=getIntent().getIntExtra("position",0);
        Log.e("图片集合",imgs.toString());
        initView();
    }

    public void initView() {
        viewpager= (NoScrollViewPager) findViewById(R.id.bigimg_viewpager);
        viewpager.setNoScroll(false);
        fragmentList = new ArrayList<Fragment>();


        if (imgs != null && imgs.size() != 0){
            for (int i = 0; i < imgs.size(); i++) {
                BigImage_Fragment testFm = new BigImage_Fragment().newInstance(i,imgs.size(),imgs.get(i));
                fragmentList.add(testFm);
            }
        }

        viewpager.setAdapter(new FragmentBigAdapter(getSupportFragmentManager(), (ArrayList<Fragment>) fragmentList));
        viewpager.setCurrentItem(position);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                viewpager.setCurrentItem(position);

            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }


    @Override
    protected void onDestroy() {
        imgs.clear();
        fragmentList.clear();
        viewpager=null;
        super.onDestroy();
    }
}
